package com.yael.tables;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.yael.utils.CacheManagerService;
import com.yael.utils.Datastore;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class NP_MESSAGE implements Serializable {

	@Persistent
	private static final long serialVersionUID = 1L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long messageID;
	
	@Persistent
	private Long processID; 
	
	@Persistent
	private String requestID; 
	
	@Persistent
	private int processStateNum;
	
	@Persistent
	private String messageType;
	
	@Persistent
	private Date messageDate;
	
	@Persistent 
	private String messageStatus;
	
	@Persistent 
	private String messageFrom;
	
	@Persistent 
	private String messageTo;
	
	@Persistent 
	private String processType;
	
	@Persistent
	private int retryNO;
	
	@Persistent
	private int versionNO;
	
	@Persistent 
	private String messageBody;
	
	@Persistent 
	private String errorCode;
	
	@Persistent 
	private String errorDesc;
	
	@Persistent 
	private String createdBY;
	
	@Persistent
	private Date creationDate;
	
	@Persistent 
	private String lastUpdateBY;
	
	@Persistent
	private Date lastUpdateDate;
	
	@Persistent
	private Long refMessageID;
	
	@Persistent
	private Date retryDate;
	
	@Persistent
	private Date actDate;
	
	@Persistent
	private Long selfNetworkID;

	public Long getMessageID() {
		return messageID;
	}

	public void setMessageID(Long messageID) {
		this.messageID = messageID;
	}

	public Long getProcessID() {
		return processID;
	}

	public void setProcessID(Long processID) {
		this.processID = processID;
	}

	public String getRequestID() {
		return requestID;
	}

	public void setRequestID(String requestID) {
		this.requestID = requestID;
	}

	public int getProcessStateNum() {
		return processStateNum;
	}

	public void setProcessStateNum(int processStateNum) {
		this.processStateNum = processStateNum;
	}

	public String getMessageType() {
		return messageType;
	}

	public void setMessageType(String messageType) {
		this.messageType = messageType;
	}

	public Date getMessageDate() {
		return messageDate;
	}

	public void setMessageDate(Date messageDate) {
		this.messageDate = messageDate;
	}

	public String getMessageStatus() {
		return messageStatus;
	}

	public void setMessageStatus(String messageStatus) {
		this.messageStatus = messageStatus;
	}

	public String getMessageFrom() {
		return messageFrom;
	}

	public void setMessageFrom(String messageFrom) {
		this.messageFrom = messageFrom;
	}

	public String getMessageTo() {
		return messageTo;
	}

	public void setMessageTo(String messageTo) {
		this.messageTo = messageTo;
	}

	public String getProcessType() {
		return processType;
	}

	public void setProcessType(String processType) {
		this.processType = processType;
	}

	public int getRetryNO() {
		return retryNO;
	}

	public void setRetryNO(int retryNO) {
		this.retryNO = retryNO;
	}

	public int getVersionNO() {
		return versionNO;
	}

	public void setVersionNO(int versionNO) {
		this.versionNO = versionNO;
	}

	public String getMessageBody() {
		return messageBody;
	}

	public void setMessageBody(String messageBody) {
		this.messageBody = messageBody;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorDesc() {
		return errorDesc;
	}

	public void setErrorDesc(String errorDesc) {
		this.errorDesc = errorDesc;
	}

	public String getCreatedBY() {
		return createdBY;
	}

	public void setCreatedBY(String createdBY) {
		this.createdBY = createdBY;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public String getLastUpdateBY() {
		return lastUpdateBY;
	}

	public void setLastUpdateBY(String lastUpdateBY) {
		this.lastUpdateBY = lastUpdateBY;
	}

	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}

	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}

	public Long getRefMessageID() {
		return refMessageID;
	}

	public void setRefMessageID(Long refMessageID) {
		this.refMessageID = refMessageID;
	}

	public Date getRetryDate() {
		return retryDate;
	}

	public void setRetryDate(Date retryDate) {
		this.retryDate = retryDate;
	}

	public Date getActDate() {
		return actDate;
	}

	public void setActDate(Date actDate) {
		this.actDate = actDate;
	}

	public Long getSelfNetworkID() {
		return selfNetworkID;
	}

	public void setSelfNetworkID(Long selfNetworkID) {
		this.selfNetworkID = selfNetworkID;
	}
	

	 public NP_MESSAGE store(PersistenceManager pm, CacheManagerService cm) {
		 NP_MESSAGE message = null;
	        try {
	        	message = pm.makePersistent(this);
	        	this.messageID = message.getMessageID();
	        	cm.setValue(Long.toString(this.messageID), this);
	        } finally {
	            pm.close();
	        }
	        return this;
	 }
	 
	 public static NP_MESSAGE retriveByID(PersistenceManager pm, CacheManagerService cs, String messageID){
		 Object object = null;
		 object = cs.getValue(messageID);
		 if(object == null) {
			 object = Datastore.retriveByID(pm, NP_MESSAGE.class, Long.parseLong(messageID));
			 cs.setValue(messageID, object);
		 }
		 if(object!=null) return (NP_MESSAGE) object;
		 return null;
	 }
}

